#!/bin/sh

echo "初始化repo源..."
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
cp -f repos/MariaDB.repo /etc/yum.repos.d/MariaDB.repo

yum -y install gcc gcc-c++
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils git zip unzip libjpeg libjpeg-devel libpng-devel freetype freetype-devel python3
yum clean all && yum makecache && yum -y update
echo "初始化repo源完成"

echo "开始系统优化..."
echo "vm.nr_hugepages=512" >> /etc/sysctl.conf
sysctl vm.nr_hugepages=512
echo "系统优化完成"

echo "开始安装nginx..."
yum install -y nginx
mkdir -p /hwdata/
cp -r www /hwdata/www
mkdir -p /hwdata/logs/nginx
chown nginx:nginx /hwdata/logs/nginx
cp -f config/nginx.conf /etc/nginx/nginx.conf
cp -f config/app.conf /etc/nginx/conf.d/app.conf
systemctl enable nginx && systemctl start nginx
echo "nginx安装完成"

echo "开始安装php74..."
yum-config-manager --enable remi-php74
yum -y install php php-mcrypt php-devel php-opcache php-cli php-pdo php-pdo_mysql php-pear php-mbstring php-mcrypt  php-gd php-pear php-curl php-fpm php-mysql php-ldap php-zip php-fileinfo 
sed -ie "s/;date.timezone =/date.timezone = Asia\/Chongqing/" /etc/php.ini
sed -ie "s/user = apache/user = nginx/" /etc/php-fpm.d/www.conf
sed -ie "s/group = apache/group = nginx/" /etc/php-fpm.d/www.conf
systemctl enable php-fpm
systemctl start php-fpm
echo "php74安装完成"


#echo "开始安装MariaDB..."
#yum install -y mariadb-server mariadb-client
#systemctl enable mariadb
#systemctl start mariadb
# 手动运行如下命令，安全初始化 
# /usr/bin/mysql_secure_installation
#echo "MariaDB安装完成"

echo "开始安装redis...."
yum install -y redis
systemctl enable redis && systemctl start redis
echo "redis安装完成"

echo "开始安装supervisord..."
# easy_install supervisor
# echo_supervisord_conf > /etc/supervisord.conf
# cp -f supervisord.conf /etc/supervisord.conf
# cp -f supervisord.service /lib/systemd/system/supervisord.service
yum install -y supervisor
systemctl daemon-reload && systemctl enable supervisord && systemctl start supervisord 
echo "supervisord安装成功"

echo "开始安装mycli..."
pip3 install mycli
echo "mycli安装成功"

echo "安装完成"



